class JobsController < ApplicationController

  before_filter :login_required, :except => [:show, :index]

  before_filter :check_auth, :only => [:edit, :update, :destroy]


  make_resourceful do
    actions :all
    response_for(:create, :update) { redirect_to job_path(@job)}
    response_for(:update_fails) { render :action => :edit}
    response_for(:create_fails) { render :action => :new}
    response_for(:destroy) { redirect_to jobs_path }

    after(:create){ current_user.jobs << @job}
  end

  def index
    @jobs = Job.paginate(:page => params[:page], :order => 'created_at DESC')
  end

  private

  def check_auth
    logged_in? and Job.find(params[:id]).user == current_user ? true : access_denied
  end
end
